package com.tql;

import redis.clients.jedis.Jedis;

import java.util.Set;

public class TestKey {
    public static void main(String[] args) {
        Jedis jedis=new Jedis("127.0.0.1",6379);
        System.out.println("清空数据库"+jedis.flushDB());
        System.out.println("添加"+jedis.set("username","tianqili"));
        System.out.println("判断某个键是否存在"+jedis.exists("username"));
        System.out.println("添加"+jedis.set("password","123456"));
        Set<String> keys=jedis.keys("*");
        System.out.println(keys);
        System.out.println("删除键"+jedis.del("password"));
        System.out.println("判断password是否存在"+jedis.exists("password"));
        System.out.println("查看键所对应的类型"+jedis.type("username"));
        System.out.println("添加"+jedis.set("id","123456"));
        System.out.println("随即返回key空间的一个"+jedis.randomKey());
        System.out.println("重命名"+jedis.rename("id","uid"));
        System.out.println("取出重命名后的key value 键值对"+jedis.get("uid"));
        System.out.println("搜索引擎查询"+jedis.select(0));
        System.out.println("清除数据库里的key value"+jedis.flushDB());
        System.out.println("查看当前数据库中key的数目"+jedis.dbSize());
        System.out.println("删除所有数据库中的所有key"+jedis.flushAll());

    }
}
